from django.db import models

class Pathway(models.Model):
    id = models.CharField(max_length=6,primary_key=True)
    name = models.CharField(max_length=100)
    def __str__(self):
      return self.name
    class Meta:
        db_table = u'kpathway'
    class Admin:
        # Admin options go here
        list_display = ('id', 'name', 'name', )

class Reaction(models.Model):
    reactionid = models.CharField(max_length=6, primary_key=True)
#    pathway = models.ForeignKey(Pathway)
    reversibility = models.CharField(max_length=1, blank=True)
    equation = models.CharField(max_length=300, blank=True)
    eq_in_id = models.CharField(max_length=150, blank=True)
    excluded=models.CharField(max_length=15, blank=True)
    def __str__(self):
      return self.reactionid
    class Meta:
        db_table = u'kreaction'
        ordering = ('reactionid',)
    class Admin:
        # Admin options go here
        list_display = ('reactionid', 'reversibility', 'equation')
        list_per_page = 100
        search_fields = ('reactionid','eq_in_id','equation',)         

class Compound(models.Model):
    compoundid = models.CharField(max_length=6, primary_key=True)
    name = models.CharField(max_length=300, blank=True)
    def __str__(self):
      return self.compoundid
    class Meta:
        # the db-table meta class define the table name
        db_table = u'kcompound'
    class Admin:
        # Admin options go here
        list_display = ('compoundid',  'name')
        ordering = ('compoundid',)
        search_fields = ('compoundid','name',)         

class Rea_ec(models.Model):
    reaction = models.ForeignKey(Reaction)
    enzyme = models.CharField(max_length=20)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.enzyme
    class Meta:
        db_table = u'krea_ec'
    class Admin:
        list_display = ('reaction', 'enzyme',)
        list_per_page = 100
        ordering = ('reaction',)
        search_fields = ('reaction','enzyme',)         

class Reako(models.Model):
    reaction = models.ForeignKey(Reaction)
    ko = models.CharField(max_length=6)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.ko
    class Meta:
        db_table = u'kreako'
    class Admin:
        list_display = ('reaction', 'ko',)
        list_per_page = 100
        ordering = ('reaction',)
        search_fields = ('reaction','ko',)         

class Reaorg(models.Model):
    reaction = models.ForeignKey(Reaction)
    org = models.CharField(max_length=5)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.reaction
    class Meta:
        db_table = u'kreaorg'
    class Admin:
        ordering = ('reaction',)
        search_fields = ('reaction','org',) 

class Rea_path(models.Model):
    reaction = models.ForeignKey(Reaction)
    path = models.ForeignKey(Pathway)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.enzyme
    class Meta:
        db_table = u'krea_path'
    class Admin:
        list_display = ('reaction', 'path',)
        ordering = ('path',)

class Met_link(models.Model):
    rea=models.ForeignKey(Reaction)
    com1 = models.ForeignKey(Compound, related_name = "substrate")
    com2 = models.ForeignKey(Compound, related_name = "product")
    class Meta:
        db_table = u'kmet_link'
    class Admin:
        list_display = ('com1', 'com2','rea',)
        list_per_page = 100
        ordering = ('com1',)
        search_fields = ('com1','com2','rea',)         

class Rea_comp(models.Model):
#serial primary key generated automatically
    id = models.IntegerField(primary_key=True)
    reaction = models.ForeignKey(Reaction)
    compound = models.ForeignKey(Compound)
    coefficient = models.CharField(max_length=5, blank=True)
    maincompound = models.CharField(max_length=1, blank=True)
    class Meta:
        db_table = u'krea_comp'
